package com.sujeet.learning.memorymanagement;

import java.util.*;
import java.util.concurrent.*;

// VMARGS: -Xms8M -Xmx16M -XX:+HeapDumpOnOutOfMemoryError

class Simple {
	Integer t;
	String s;

	public Simple(Integer a, String b) {
		t = a;
		s = b;
	}
}

public class OutOfMemory {

	public static List<Simple> list = new ArrayList<Simple>();

	public static synchronized void showSize() {
		//System.out.println("Size of array " + list.size());
	}

	public static void main(String[] args) {
		ExecutorService es = Executors.newFixedThreadPool(1);
		es.submit(new Runnable() {
			public void run() {
				while (true) {
					showSize();
				}
			}
		});
		int i = 0;
		while (true) {
			Simple item = new Simple(i, String.valueOf(i));
			list.add(item);
			//System.out.println(item);
			++i;
		}
	}
}
